﻿using System;
using System.Data;
using System.Collections.Generic;
using DataLib.Common;
using DataLib.Model;
using DataLib.Accounts.Bus;

namespace DataLib.BLL
{
	/// <summary>
	/// cum_aacounts
	/// </summary>
	public partial class cum_aacounts
	{
		private readonly DataLib.DAL.cum_aacounts dal=new DataLib.DAL.cum_aacounts();
		public cum_aacounts()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int cumid,int accountid)
		{
			return dal.Exists(cumid,accountid);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(DataLib.Model.cum_aacounts model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DataLib.Model.cum_aacounts model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int cumid,int accountid)
		{
			
			return dal.Delete(cumid,accountid);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.cum_aacounts GetModel(int cumid,int accountid)
		{
			
			return dal.GetModel(cumid,accountid);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public DataLib.Model.cum_aacounts GetModelByCache(int cumid,int accountid)
		{
			
			string CacheKey = "cum_aacountsModel-" + cumid+accountid;
			object objModel = DataLib.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(cumid,accountid);
					if (objModel != null)
					{
						int ModelCache = DataLib.Common.ConfigHelper.GetConfigInt("ModelCache");
						DataLib.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (DataLib.Model.cum_aacounts)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.cum_aacounts> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DataLib.Model.cum_aacounts> DataTableToList(DataTable dt)
		{
			List<DataLib.Model.cum_aacounts> modelList = new List<DataLib.Model.cum_aacounts>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DataLib.Model.cum_aacounts model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
				}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 获取LTR数据集
        /// </summary>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public DataTable getLTRWhere(string strwhere)
        {
            return dal.getLTRWhere(strwhere);
        }

               /// <summary>
        /// 根据客户ID取得用户帐号
        /// </summary>
        /// <param name="comid"></param>
        /// <returns></returns>
        public User getUserByComId(int comid)
        {
            return dal.getUserByComId(comid);
        }

        
        /// <summary>
        /// 根据userid获取客户帐号
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public Model.Cumtomer GetCumByUserid(int userid)
        {
            return dal.GetCumByUserid(userid);
        }

                /// <summary>
        /// 根据登陆用户获取客户的LoadNum列表
        /// </summary>
        /// <param name="blongCity">归属城市</param>
        /// <param name="Depart">登陆人员部门</param>
        /// <param name="userid">用户的系统ID</param>
        /// <param name="username">用户帐号</param>
        /// <param name="usertype">用户类型</param>
        /// <returns></returns>
        public DataTable GETLoadListByCumtomer(int userid, string username, string usertype, string blongCity, string Depart)
        {
            return dal.GETLoadListByCumtomer(userid, username, usertype, blongCity, Depart);
        }

        /// <summary>
        /// 根据登陆用户获取客户的LoadNum列表
        /// </summary>
        /// <param name="blongCity">归属城市</param>
        /// <param name="userid">用户的系统ID</param>
        /// <param name="username">用户帐号</param>
        /// <param name="usertype">用户类型</param>
        /// <param name="BarTab">需要汇总的表</param>
        /// <param name="curStatus">实时状态</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="goodsName">物品名称</param>
        /// <param name="loadno">Load号</param>
        /// <returns></returns>
        public DataTable GETBarByCumtomer(int userid, string username, string usertype, string blongCity, string loadno, string goodsName, string strtDate, string endDate, int curStatus, out DataTable BarTab)
        {
            return dal.GETBarByCumtomer(userid, username, usertype, blongCity, loadno, goodsName, strtDate, endDate, curStatus, out BarTab);
        }


        public DataTable GetCumAccountList(string belong)
        {
            return dal.GetCumAccountList(belong);
        }

        public DataTable CumAccountListDetile(int cumid)
        {
            return dal.CumAccountListDetile(cumid);
        }

               /// <summary>
        /// 获取LTR数据集
        /// </summary>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public DataTable GetLtrList(string loadno, string loaddate
                , string cumcode, string cumname, string colldate, string collmonth, string gcity
                , string CEcaiwu, string CAcum, string CumSname, string cjosaleman, string remark
                ,string nwt,string wrldate,string goodsinfo,string tallydate,string pname,string bcity)
        {
            return dal.GetLtrList(loadno, loaddate, cumcode, cumname, colldate, collmonth, gcity, CEcaiwu, CAcum, CumSname, cjosaleman, remark,nwt,wrldate,goodsinfo,tallydate,pname,bcity);
        }

        
        /// <summary>
        /// 获取
        /// </summary>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public String GetCumUserName(string cumcode)
        {
            return dal.GetCumUserName(cumcode);
        }

               /// <summary>
        /// 根据客户ID取得客户下的所有帐号列表
        /// </summary>
        /// <param name="cumid"></param>
        /// <returns></returns>
        public DataTable GetUserListByCumid(string cumid)
        {
            return dal.GetUserListByCumid(cumid);
        }
		#endregion  ExtensionMethod
	}
}

